<?php
/**
 * 设置考评主管
 */
apf_require_controller("Abstract");
apf_require_class("Bll_Jx_Setting");
apf_require_class("Util_ApioAuth");
class Ajax_ChangeSuperiorController extends AbstractController {

    public function handle_request() {
        $bll=new Bll_Jx_Setting();
        $params=APF::get_instance()->get_request()->get_parameters();
        if($params['type']=='search_underling')
        {
        if($params['id']){
        $native=$bll->get_member_by_code($params['id']);
        }
        if(!$native){
        $info=Util_ApioAuth::get_user_info_by_api($params['id']);
        if($info!='[]'){
            $u=json_decode($info);
            $uu=(array)$u[0];
            $underlings=$bll->get_underling_info($uu['code']);
            $this->json_encode(1,$underlings);
        }else 
        
        {
            $this->json_encode(1,"none");
        }
        
        }
        else {
        $underlings=$bll->get_underling_info($params['id']);
        $this->json_encode(1,$underlings);
        }
        }
        if($params['type']=='search_superior' && $params['id'])
        {
        $superior=$bll->get_superior_id($params['id']);
        if(!$superior){
        $info=Util_ApioAuth::get_user_info_by_api($params['id']);
        if($info!='[]'){
            $u=json_decode($info);
            $uu=(array)$u[0];
            $this->json_encode(1,$uu);
        }else
        
        {
         $this->json_encode(1,"none");
        }
        
        }
        else {
        $this->json_encode(1, $superior);
        }
        }
        if($params['id'] && $params['id_new'])
        {
        $infos=$bll->get_underling_info($params['id']);
        $ids=array();
        if($infos)
        {
        foreach ($infos as $info)
        {
            array_push($ids,$info['code']);
        }
        }
        $status=$bll->set_superior($ids,$params['id_new']);
        if($status){
            $this->json_encode(1,"ok");
        }
        }
    }
}